package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entities.User;

/**
 * Servlet implementation class OverviewServlet
 */
@WebServlet("/Overview")
public class OverviewServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public OverviewServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User user = (User) request.getSession().getAttribute("user");
		String username = "";
		if(user != null){
			System.out.println(user.toString());
			username = user.getUsername();
		}else{		
			username = request.getParameter("username");
		}
		
		if(username != null){
			request.getSession().setAttribute("user", user);
			request.getRequestDispatcher("WEB-INF/Overview.jsp").forward(request, response);
		}else
			response.sendRedirect("index.jsp");
	}

}
